package leetcode.Tree;

import javax.swing.tree.TreeNode;

/**
 * Created by Admin on 2020/7/28.
 */
public class Question104 {


    static public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        } else {
            int leftHeight = maxDepth(root.left);
            int rightHeight = maxDepth(root.right);
            return Math.max(leftHeight, rightHeight) + 1;
        }

    }

    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public static void main(String[] args) {
        TreeNode treeNode = new TreeNode(3);
        treeNode.left = new TreeNode(9);
        treeNode.right = new TreeNode(20);

        treeNode.right.right = new TreeNode(7);
        treeNode.right.left = new TreeNode(15);
        System.out.println(maxDepth(treeNode));
    }
}
